// pages/swiperdetail/swiperdetail.js
var that,
  api = new (require('../../utils/api.js')),
  WxParse = require('../../wxParse/wxParse.js'),
  headimg = api.getimgurl(),
  headaudio = api.getaudiourl(),
  app = getApp(),
  util = new (require('../../utils/util.js'));
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orders:'',
    parenting_price:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    that=this
    let {id}=options,{orders,parenting_price}=that.data,isnine=wx.getStorageSync('isnine')
    that.setData({isnine,id})
    if (app.logininfo) {
      that.getdata()
      console.log(0)
    } else {
      util.setwatcher(app, this.afterlogin)
    }
  },
  afterlogin: {
    token: res => {
      that.getdata();
    }
  },
  getdata(){
    let {id,orders,parenting_price} =that.data
    api.getswiperdetail(id,res=>{
      if(res.data.issuccess==1){
        console.log(res.data,'getallswipergetallswipergetallswiper')
        var article=that.replaceraw(decodeURIComponent(res.data.data.detail));
        orders=res.data.data.orders
        that.setData({orders})
        console.log(orders,'articleva')
        WxParse.wxParse('article', 'html', article, that, 5);
      }
    })
    api.getsetting( res => {
      if (res.data.issuccess == 1) {
        parenting_price=res.data.data.parenting_price;
        that.setData({parenting_price})
        console.log(parenting_price)
      }
    });
  },
   replaceraw(content) {
       return content.replace('rgb(', 'rgb').replace(new RegExp('rgb', 'g'), "rgb(");
   },
   topay(){
    let openid =wx.getStorageSync('openid'),{parenting_price,isnine}=that.data,data = {openid,total:parenting_price};
    that.setData({isnine})
        api.parentingpay(data,res => {
          if (res.succ == 1) {
            that.setData({payshow:!1})
            if(isnine=='0'){
              api.setnine(res =>{
                if(res.data.issuccess == 1){
                }
              })
            }
          } 
        })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: app.logininfo.appletname,
      path: `pages/listen/listen?share=`+app.logininfo.userid,
    }
  }
})